Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[InputBase] Remove legacy lifecycle methods #13487

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Nov 1, 2018

Removes legacy lifecycle methods that would require legacy context API. cWRP -> gDSFP, cWU -> cDU.

Preface: Allowing users to handle inputs in a mix of context and props should not be allowed in future implementations. Either the Provider or the Component should be the source of truth.

There will be breakage if this component was handled in a mixed way between controlled via props vs controlled via context e.g.

- <FormControl disabled={true}><InputBase disabled={false} /></FormControl>
+ <FormControl disabled={true}><InputBase disabled={undefined} /></FormControl>

This would previously switch the formControlState from not disabled to disabled because it only uses context if the prop is undefined. This would would trigger setState({ focused: false }) in cWRP. However we don't have access to context in gDSFP so now the input would still be focused and onBlur will not fire.

I see no other way forward and actually a fix. I hope nobody relied on this.

Other issues:

- <FormControl disabled={false}><InputBase /></FormControl>
+ <FormControl disabled={true}><InputBase /></FormControl>

context.onBlue() won't get fired as well as It won't be necessary since we have gDSFP in the FormControll

state.focused won't be reset. Seems like we really need to split this component up. Fixed in d9ff717

if (!prevProps.disabled && this.props.disabled) {
const { muiFormControl } = this.context;
if (muiFormControl && muiFormControl.onBlur) {
muiFormControl.onBlur();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something that should go to the chopping block in a major. Why would someone put the component into the context if he then controls it via props on InputBase rather than props on `FormControl``

@eps1lon eps1lon changed the title WIP: [InputBase] Remove legacy lifecycle methods [InputBase] Remove legacy lifecycle methods Nov 2, 2018
@@ -48,6 +48,13 @@ export const styles = {
* ⚠️ Only one input can be used within a FormControl.
*/
class FormControl extends React.Component {
static getDerivedStateFromProps(props, state) {
Copy link
Member

@oliviertassinari oliviertassinari Nov 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it's the InputBase that should take care of it by calling handleBlur. Why do we need this logic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- <FormControl disabled={false}><InputBase /></FormControl>
+ <FormControl disabled={true}><InputBase /></FormControl>

InputBase already calls handleBlur separately if it's own focused state changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow, the disable change will propagate down to the input.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need an integration test? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's context not props propagation. If you think that some behavior was already covered feel free to add a test. Especially focused was not considered correctly.

But why should InputBase call onBlur in it's parent when the parent got changed and can take care of itself? No need to delegate that logic into the child.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The form control should propagate the disabled state to the input with the context. The input can then collect it. This way, we can avoid logic duplication. I think that we should remove the old context usage at the same time this logic is very dependant on the context implementation. I think that it will be simpler and less error prone to do both at the same time.

Yeah, it would be great to have an integration tests. It's tricky. Well, I'm also fine with logic duplication if it's simpler.

Copy link
Member Author

@eps1lon eps1lon Nov 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only logic duplication if you have a mental model with the old context and lifecycle methods. I don't think the discussion is helpful here. If you know how to access context in gDSFP or cDU I'd be happy to change it but I don't know how.

this logic is very dependant on the context implementation.

I can only work with what's been given to me. InputBase was always tightly coupled with the context.

Copy link
Member

@oliviertassinari oliviertassinari Nov 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gDSFP or cDU I'd be happy to change it but I don't know how.

We can't, it's why I'm raising the new context api, where we would be injecting the context as properties.

@oliviertassinari oliviertassinari added new feature New feature or request component: text field This is the name of the generic UI component, not the React module! labels Nov 5, 2018
@oliviertassinari oliviertassinari merged commit 4478063 into mui:master Nov 5, 2018
@eps1lon eps1lon deleted the fix/core/InputBase/legacy-lifecycle-methods branch December 5, 2018 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants